package server.utils;

import java.net.Socket;
import DAO.TotalDao;
import model.*;
import server.main.*;
import java.util.*;

import com.google.gson.Gson;

public class LoginChecker {
	private DAO.TotalDao totaldao;
	
	public Message check(int account,String pwd) {
		totaldao = new DAO.TotalDao(server_main.db.con);
		int result = totaldao.userLogin(account, pwd);
		Message mes = new Message();
		
		if(result > 0) {
			mes.setUserID(result);
			mes.setType(MsgType.LOGIN_SUCCEED);
			//Vector<String> v = totaldao.userRooms(result);
			Hashtable<Integer, String> friends = totaldao.userFriends(account);
			Gson gson = new Gson();
			//String vjson = gson.toJson(v);
			String fjson = gson.toJson(friends);
			System.out.println(fjson);
			mes.setText(fjson);
			System.out.println(mes.getType());
			return mes;
			
		}else if(result == -1) {
			mes.setType(MsgType.LOGIN_FAILED_WRONG);
			return mes;
		}else if(result == -2) {
			mes.setType(MsgType.LOGIN_FAILED_NOACCOUNT);
			return mes;
		}
		return null;
	}
}
